package com.example.lmy.okgotestdemo;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

public class TestOkGoActivity extends AppCompatActivity implements View.OnClickListener {


    private Button Get;
    private Button Post;
    private Button Put;
    private Button Delete;



    public static void show(Context context){
        context.startActivity(new Intent(context,TestOkGoActivity.class));
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_ok_go);
        Get = (Button) findViewById(R.id.Get);
        Post = (Button) findViewById(R.id.Post);
        Put = (Button) findViewById(R.id.Put);
        Delete = (Button) findViewById(R.id.Delete);
        Get.setOnClickListener(this);
        Post.setOnClickListener(this);
        Put.setOnClickListener(this);
        Delete.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.Get:
                OkGo.<String>get("http://result.eolinker.com/S3RELJt24d2b780deae3dec4610bbcaf238d0e56d25fb53?uri=/app/ceshi")//
                        .tag(this)//
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(Response<String> response) {
                                //注意这里已经是在主线程了
                                String data = response.body();//这个就是返回来的结果
                                Log.d("GetData","返回的数据"+data);
                            }
                            @Override
                            public void onError(Response<String> response) {
                                super.onError(response);
                            }
                        });
                break;
            case R.id.Post:
                break;
            case R.id.Put:
                break;
            case R.id.Delete:
                break;
        }
    }
}
